{\rtf1\ansi\deff0\adeflang1025
{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset0 Times New Roman;}{\f2\fnil\fprq0\fcharset0 Courier New;}{\f3\froman\fprq2\fcharset0 Thorndale{\*\falt Times New Roman};}{\f4\fswiss\fprq2\fcharset0 Albany{\*\falt Arial};}{\f5\fnil\fprq2\fcharset0 Arial;}{\f6\fnil\fprq0\fcharset0 Verdana;}{\f7\fnil\fprq2\fcharset0 HG Mincho Light J{\*\falt msmincho};}{\f8\fnil\fprq2\fcharset0 Arial Unicode MS;}}
{\colortbl;\red0\green0\blue0;\red0\green0\blue128;\red255\green255\blue255;\red128\green128\blue128;}
{\stylesheet{\s1\li86\ri86\lin86\rin86\fi0\sb86\sa86\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\loch\f6\fs20\lang1033\snext1 Normal;}
{\s2\li86\ri86\lin86\rin86\fi0\sb240\sa283\keepn\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af8\afs28\lang255\ltrch\dbch\af7\langfe255\hich\f4\fs28\lang1033\loch\f4\fs28\lang1033\sbasedon1\snext3 Heading;}
{\s3\li0\ri0\lin0\rin0\fi0\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\loch\f6\fs20\lang1033\sbasedon1\snext3 Body Text;}
{\s4\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\loch\f6\fs20\lang1033\sbasedon3\snext4 List;}
{\s5\li86\ri86\lin86\rin86\fi0\sb120\sa120\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs24\lang255\ai\ltrch\dbch\af6\langfe255\hich\f6\fs24\lang1033\i\loch\f6\fs24\lang1033\i\sbasedon1\snext5 caption;}
{\s6\li86\ri86\lin86\rin86\fi0\sb86\sa86\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\loch\f6\fs20\lang1033\sbasedon1\snext6 Index;}
{\s7\li86\ri86\lin86\rin86\fi0\sa283\brdrb\brdrdb\brdrw15\brdrcf4\brsp0{\*\brdrb\brdlncol4\brdlnin1\brdlnout1\brdlndist20}\brsp0\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs12\lang1033\loch\f6\fs12\lang1033\sbasedon1\snext3 Horizontal Line;}
{\s8\li86\ri86\lin86\rin86\fi0\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\i\loch\f6\fs20\lang1033\i\sbasedon1\snext8 envelope return;}
{\s9\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\loch\f6\fs20\lang1033\sbasedon3\snext9 Table Contents;}
{\s10\li86\ri86\lin86\rin86\fi0\sb86\sa86\cf0{\*\tlswg8236}\tqc\tx4904{\*\tlswg8236}\tqr\tx9723{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\loch\f6\fs20\lang1033\sbasedon1\snext10 footer;}
{\s11\li86\ri86\lin86\rin86\fi0\sb86\sa86\cf0{\*\tlswg8236}\tqc\tx4904{\*\tlswg8236}\tqr\tx9723{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\loch\f6\fs20\lang1033\sbasedon1\snext11 header;}
{\s12\li86\ri86\lin86\rin86\fi0\sb240\sa283\keepn\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af8\afs48\lang255\ab\ltrch\dbch\af7\langfe255\hich\f3\fs48\lang1033\b\loch\f3\fs48\lang1033\b\sbasedon2\snext3{\*\soutlvl0} heading 1;}
{\s13\li86\ri86\lin86\rin86\fi0\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af2\afs20\lang255\ltrch\dbch\af2\langfe255\hich\f2\fs20\lang1033\loch\f2\fs20\lang1033\sbasedon1\snext13 Preformatted Text;}
{\*\cs15\cf0\rtlch\af5\afs24\lang255\ltrch\dbch\af5\langfe255\hich\f0\fs24\lang1033\loch\f0\fs24\lang1033 Endnote Symbol;}
{\*\cs16\cf0\rtlch\af5\afs24\lang255\ltrch\dbch\af5\langfe255\hich\f0\fs24\lang1033\loch\f0\fs24\lang1033 Footnote Symbol;}
{\*\cs17\cf2\ul\ulc0\rtlch\af5\afs24\lang255\ltrch\dbch\af5\langfe255\hich\f0\fs24\lang1033\loch\f0\fs24\lang1033 Internet link;}
}
{\info{\title GenerareInsertStatementScript}{\creatim\yr2009\mo4\dy22\hr4\min52}{\revtim\yr1601\mo1\dy1\hr0\min0}{\printim\yr1601\mo1\dy1\hr0\min0}{\comment StarWriter}{\vern6800}}\deftab709
{\*\pgdsctbl
{\pgdsc0\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\pgdscnxt0 Standard;}
{\pgdsc1\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\pgdscnxt1 Endnote;}
{\pgdsc2\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn567\margtsxn567\margbsxn567{\cbpat3}\pgdscnxt2 HTML;}}
{\*\pgdscno2}\paperh15840\paperw12240\margl1134\margr567\margt567\margb567\sectd\sbknone\pgwsxn12240\pghsxn15840\marglsxn1134\margrsxn567\margtsxn567\margbsxn567{\cbpat3}\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc
\pard\plain \ltrpar\s3\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\li0\ri0\lin0\rin0\fi0\rtlch\af6\afs20\lang255\ltrch\dbch\af6\langfe255\hich\f6\fs20\lang1033\loch\f6\fs20\lang1033 {\rtlch \ltrch\loch\f6\fs20\lang1033\i0\b0 \line \line \line CREATE PROC [dbo].[spgenerate_inserts_2]\line (\line @table_name varchar(776), -- The table/view for which the INSERT statements will be generated using the existing data\line @target_table varchar(776) = NULL, -- Use this parameter to specify a different table name i
nto which the data will be inserted\line @include_column_list bit = 1, -- Use this parameter to include/ommit column list in the generated INSERT statement\line @from varchar(800) = NULL, -- Use this parameter to filter the rows based on a filter condition (using WH
ERE)\line @include_timestamp bit = 0, -- Specify 1 for this parameter, if you want to include the TIMESTAMP/ROWVERSION column's data in the INSERT statement\line @debug_mode bit = 0, -- If @debug_mode is set to 1, the SQL statements constructed by this procedure wil
l be printed for later examination\line @owner varchar(64) = NULL, -- Use this parameter if you are not the owner of the table\line @ommit_images bit = 0, -- Use this parameter to generate INSERT statements by omitting the 'image' columns\line @ommit_identity bit = 0, --
 Use this parameter to ommit the identity columns\line @top int = NULL, -- Use this parameter to generate INSERT statements only for the TOP n rows\line @cols_to_include varchar(8000) = NULL, -- List of columns to be included in the INSERT statement\line @cols_to_exclude
 varchar(8000) = NULL, -- List of columns to be excluded from the INSERT statement\line @disable_constraints bit = 0, -- When 1, disables foreign key constraints and enables them after the INSERT statements\line @ommit_computed_cols bit = 0, -- When 1, computed colu
mns will not be included in the INSERT statement\line @where varchar(1000) = '' -- Where clause\line )\line AS\line BEGIN\line /***********************************************************************************************************\line Procedure: sp_generate_inserts (Build 22)\line (Co
pyright c 2002 Narayana Vyas Kondreddi. All rights reserved.)\line \line Purpose: To generate INSERT statements from existing data.\line These INSERTS can be executed to regenerate the data at some other location.\line This procedure is also useful to create a database setup,
 where in you can\line script your data along with your table definitions.\line Written by: Narayana Vyas Kondreddi\line http://vyaskn.tripod.com\line Acknowledgements:\line Divya Kalra -- For beta testing\line Mark Charsley -- For reporting a problem with scripting uniqueidentifier co
lumns with NULL values\line Artur Zeygman -- For helping me simplify a bit of code for handling non-dbo owned tables\line Joris Laperre -- For reporting a regression bug in handling text/ntext columns\line Tested on: SQL Server 7.0 and SQL Server 2000\line Date created: Janua
ry 17th 2001 21:52 GMT\line Date modified: May 1st 2002 19:50 GMT\line Email: vyaskn@hotmail.com\line NOTE: This procedure may not work with tables with too many columns.\line Results can be unpredictable with huge text columns or SQL Server 2000's sql_variant data types\line When
ever possible, Use @include_column_list parameter to ommit column list in the INSERT statement, for better results\line IMPORTANT: This procedure is not tested with internation data (Extended characters or Unicode). If needed\line you might want to convert the datat
ypes of character variables in this procedure to their respective unicode counterparts\line like nchar and nvarchar\line \line Example 1: To generate INSERT statements for table 'titles':\line \line EXEC sp_generate_inserts 'titles'\line Example 2: To ommit the column list in the INSER
T statement: (Column list is included by default)\line IMPORTANT: If you have too many columns, you are advised to ommit column list, as shown below,\line to avoid erroneous results\line \line EXEC sp_generate_inserts 'titles', @include_column_list = 0\line Example 3: To generate 
INSERT statements for 'titlesCopy' table from 'titles' table:\line EXEC sp_generate_inserts 'titles', 'titlesCopy'\line Example 4: To generate INSERT statements for 'titles' table for only those titles\line which contain the word 'Computer' in them:\line NOTE: Do not complica
te the FROM or WHERE clause here. It's assumed that you are good with T-SQL if you are using this parameter\line EXEC sp_generate_inserts 'titles', @from = "from titles where title like '%Computer%'"\line Example 5: To specify that you want to include TIMESTAMP colu
mn's data as well in the INSERT statement:\line (By default TIMESTAMP column's data is not scripted)\line EXEC sp_generate_inserts 'titles', @include_timestamp = 1\line Example 6: To print the debug information:\line \line EXEC sp_generate_inserts 'titles', @debug_mode = 1\line Example
 7: If you are not the owner of the table, use @owner parameter to specify the owner name\line To use this option, you must have SELECT permissions on that table\line EXEC sp_generate_inserts Nickstable, @owner = 'Nick'\line Example 8: To generate INSERT statements for t
he rest of the columns excluding images\line When using this otion, DO NOT set @include_column_list parameter to 0.\line EXEC sp_generate_inserts imgtable, @ommit_images = 1\line Example 9: To generate INSERT statements excluding (ommiting) IDENTITY columns:\line (By default 
IDENTITY columns are included in the INSERT statement)\line EXEC sp_generate_inserts mytable, @ommit_identity = 1\line Example 10: To generate INSERT statements for the TOP 10 rows in the table:\line \line EXEC sp_generate_inserts mytable, @top = 10\line Example 11: To generate IN
SERT statements with only those columns you want:\line \line EXEC sp_generate_inserts titles, @cols_to_include = "'title','title_id','au_id'"\line Example 12: To generate INSERT statements by omitting certain columns:\line \line EXEC sp_generate_inserts titles, @cols_to_exclude = 
"'title','title_id','au_id'"\line Example 13: To avoid checking the foreign key constraints while loading data with INSERT statements:\line \line EXEC sp_generate_inserts titles, @disable_constraints = 1\line Example 14: To exclude computed columns from the INSERT statement:\line 
EXEC sp_generate_inserts MyTable, @ommit_computed_cols = 1\line ***********************************************************************************************************/\line SET NOCOUNT ON\line --Making sure user only uses either @cols_to_include or @cols_to_exclude\line 
IF ((@cols_to_include IS NOT NULL) AND (@cols_to_exclude IS NOT NULL))\line BEGIN\line RAISERROR('Use either @cols_to_include or @cols_to_exclude. Do not use both the parameters at once',16,1)\line RETURN -1 --Failure. Reason: Both @cols_to_include and @cols_to_exclude p
arameters are specified\line END\line --Making sure the @cols_to_include and @cols_to_exclude parameters are receiving values in proper format\line IF ((@cols_to_include IS NOT NULL) AND (PATINDEX('''%''',@cols_to_include) = 0))\line BEGIN\line RAISERROR('Invalid use of @cols_to_i
nclude property',16,1)\line PRINT 'Specify column names surrounded by single quotes and separated by commas'\line PRINT 'Eg: EXEC sp_generate_inserts titles, @cols_to_include = "''title_id'',''title''"'\line RETURN -1 --Failure. Reason: Invalid use of @cols_to_include pr
operty\line END\line IF ((@cols_to_exclude IS NOT NULL) AND (PATINDEX('''%''',@cols_to_exclude) = 0))\line BEGIN\line RAISERROR('Invalid use of @cols_to_exclude property',16,1)\line PRINT 'Specify column names surrounded by single quotes and separated by commas'\line PRINT 'Eg: EXEC sp
_generate_inserts titles, @cols_to_exclude = "''title_id'',''title''"'\line RETURN -1 --Failure. Reason: Invalid use of @cols_to_exclude property\line END\line --Checking to see if the database name is specified along wih the table name\line --Your database context should be 
local to the table for which you want to generate INSERT statements\line --specifying the database name is not allowed\line IF (PARSENAME(@table_name,3)) IS NOT NULL\line BEGIN\line RAISERROR('Do not specify the database name. Be in the required database and just specify the 
table name.',16,1)\line RETURN -1 --Failure. Reason: Database name is specified along with the table name, which is not allowed\line END\line --Checking for the existence of 'user table' or 'view'\line --This procedure is not written to work on system tables\line --To script the d
ata in system tables, just create a view on the system tables and script the view instead\line IF @owner IS NULL\line BEGIN\line IF ((OBJECT_ID(@table_name,'U') IS NULL) AND (OBJECT_ID(@table_name,'V') IS NULL))\line BEGIN\line RAISERROR('User table or view not found.',16,1)\line PRINT
 'You may see this error, if you are not the owner of this table or view. In that case use @owner parameter to specify the owner name.'\line PRINT 'Make sure you have SELECT permission on that table or view.'\line RETURN -1 --Failure. Reason: There is no user table 
or view with this name\line END\line END\line ELSE\line BEGIN\line IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @table_name AND (TABLE_TYPE = 'BASE TABLE' OR TABLE_TYPE = 'VIEW') AND TABLE_SCHEMA = @owner)\line BEGIN\line RAISERROR('User table or view not found.
',16,1)\line PRINT 'You may see this error, if you are not the owner of this table. In that case use @owner parameter to specify the owner name.'\line PRINT 'Make sure you have SELECT permission on that table or view.'\line RETURN -1 --Failure. Reason: There is no user t
able or view with this name\line END\line END\line --Variable declarations\line DECLARE @Column_ID int,\line @Column_List varchar(8000),\line @Column_Name varchar(128),\line @Start_Insert varchar(786),\line @Data_Type varchar(128),\line @Actual_Values varchar(8000), --This is the string that will be 
finally executed to generate INSERT statements\line @IDN varchar(128) --Will contain the IDENTITY column's name in the table\line --Variable Initialization\line SET @IDN = ''\line SET @Column_ID = 0\line SET @Column_Name = ''\line SET @Column_List = ''\line SET @Actual_Values = ''\line IF @owner
 IS NULL\line BEGIN\line SET @Start_Insert = 'INSERT INTO ' + '[' + RTRIM(COALESCE(@target_table,@table_name)) + ']'\line END\line ELSE\line BEGIN\line SET @Start_Insert = 'INSERT ' + '[' + LTRIM(RTRIM(@owner)) + '].' + '[' + RTRIM(COALESCE(@target_table,@table_name)) + ']'\line END\line --To ge
t the first column's ID\line SELECT @Column_ID = MIN(ORDINAL_POSITION)\line FROM INFORMATION_SCHEMA.COLUMNS (NOLOCK)\line WHERE TABLE_NAME = @table_name AND\line (@owner IS NULL OR TABLE_SCHEMA = @owner)\line --Loop through all the columns of the table, to get the column names and
 their data types\line WHILE @Column_ID IS NOT NULL\line BEGIN\line SELECT @Column_Name = QUOTENAME(COLUMN_NAME),\line @Data_Type = DATA_TYPE\line FROM INFORMATION_SCHEMA.COLUMNS (NOLOCK)\line WHERE ORDINAL_POSITION = @Column_ID AND\line TABLE_NAME = @table_name AND\line (@owner IS NULL OR TABLE
_SCHEMA = @owner)\line IF @cols_to_include IS NOT NULL --Selecting only user specified columns\line BEGIN\line IF CHARINDEX( '''' + SUBSTRING(@Column_Name,2,LEN(@Column_Name)-2) + '''',@cols_to_include) = 0\line BEGIN\line GOTO SKIP_LOOP\line END\line END\line IF @cols_to_exclude IS NOT NULL --S
electing only user specified columns\line BEGIN\line IF CHARINDEX( '''' + SUBSTRING(@Column_Name,2,LEN(@Column_Name)-2) + '''',@cols_to_exclude) <> 0\line BEGIN\line GOTO SKIP_LOOP\line END\line END\line --Making sure to output SET IDENTITY_INSERT ON/OFF in case the table has an IDENTITY co
lumn\line IF (SELECT COLUMNPROPERTY( OBJECT_ID(QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + @table_name),SUBSTRING(@Column_Name,2,LEN(@Column_Name) - 2),'IsIdentity')) = 1\line BEGIN\line IF @ommit_identity = 0 --Determing whether to include or exclude the IDENTITY co
lumn\line SET @IDN = @Column_Name\line ELSE\line GOTO SKIP_LOOP\line END\line \line --Making sure whether to output computed columns or not\line IF @ommit_computed_cols = 1\line BEGIN\line IF (SELECT COLUMNPROPERTY( OBJECT_ID(QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + @table_name),SUBSTRING(@Col
umn_Name,2,LEN(@Column_Name) - 2),'IsComputed')) = 1\line BEGIN\line GOTO SKIP_LOOP\line END\line END\line \line --Tables with columns of IMAGE data type are not supported for obvious reasons\line IF(@Data_Type in ('image'))\line BEGIN\line IF (@ommit_images = 0)\line BEGIN\line RAISERROR('Tables with image co
lumns are not supported.',16,1)\line PRINT 'Use @ommit_images = 1 parameter to generate INSERTs for the rest of the columns.'\line PRINT 'DO NOT ommit Column List in the INSERT statements. If you ommit column list using @include_column_list=0, the generated INSERTs 
will fail.'\line RETURN -1 --Failure. Reason: There is a column with image data type\line END\line ELSE\line BEGIN\line GOTO SKIP_LOOP\line END\line END\line --Determining the data type of the column and depending on the data type, the VALUES part of\line --the INSERT statement is generated. Care is 
taken to handle columns with NULL values. Also\line --making sure, not to lose any data from flot, real, money, smallmomey, datetime columns\line SET @Actual_Values = @Actual_Values +\line CASE\line WHEN @Data_Type IN ('char','varchar','nchar','nvarchar')\line THEN\line 'COALESCE('''''
''' + REPLACE(RTRIM(' + @Column_Name + '),'''''''','''''''''''')+'''''''',''NULL'')'\line WHEN @Data_Type IN ('datetime','smalldatetime')\line THEN\line 'COALESCE('''''''' + RTRIM(CONVERT(char,' + @Column_Name + ',109))+'''''''',''NULL'')'\line WHEN @Data_Type IN ('uniqueiden
tifier')\line THEN\line 'COALESCE('''''''' + REPLACE(CONVERT(char(255),RTRIM(' + @Column_Name + ')),'''''''','''''''''''')+'''''''',''NULL'')'\line WHEN @Data_Type IN ('text','ntext')\line THEN\line 'COALESCE('''''''' + REPLACE(CONVERT(char(8000),' + @Column_Name + '),'''''''','''
''''''''')+'''''''',''NULL'')'\line WHEN @Data_Type IN ('binary','varbinary')\line THEN\line 'COALESCE(RTRIM(CONVERT(char,' + 'CONVERT(int,' + @Column_Name + '))),''NULL'')'\line WHEN @Data_Type IN ('timestamp','rowversion')\line THEN\line CASE\line WHEN @include_timestamp = 0\line THEN\line '''DEFAU
LT'''\line ELSE\line 'COALESCE(RTRIM(CONVERT(char,' + 'CONVERT(int,' + @Column_Name + '))),''NULL'')'\line END\line WHEN @Data_Type IN ('float','real','money','smallmoney')\line THEN\line 'COALESCE(LTRIM(RTRIM(' + 'CONVERT(char, ' + @Column_Name + ',2)' + ')),''NULL'')'\line ELSE\line 'COALESCE(
LTRIM(RTRIM(' + 'CONVERT(char, ' + @Column_Name + ')' + ')),''NULL'')'\line END + '+' + ''',''' + ' + '\line \line --Generating the column list for the INSERT statement\line SET @Column_List = @Column_List + @Column_Name + ','\line SKIP_LOOP: --The label used in GOTO\line SELECT @Colum
n_ID = MIN(ORDINAL_POSITION)\line FROM INFORMATION_SCHEMA.COLUMNS (NOLOCK)\line WHERE TABLE_NAME = @table_name AND\line ORDINAL_POSITION > @Column_ID AND\line (@owner IS NULL OR TABLE_SCHEMA = @owner)\line --Loop ends here!\line END\line --To get rid of the extra characters that got concate
nated during the last run through the loop\line SET @Column_List = LEFT(@Column_List,len(@Column_List) - 1)\line SET @Actual_Values = LEFT(@Actual_Values,len(@Actual_Values) - 6)\line IF LTRIM(@Column_List) = ''\line BEGIN\line RAISERROR('No columns to select. There should at leas
t be one column to generate the output',16,1)\line RETURN -1 --Failure. Reason: Looks like all the columns are ommitted using the @cols_to_exclude parameter\line END\line --Forming the final string that will be executed, to output the INSERT statements\line IF (@include_colum
n_list <> 0)\line BEGIN\line SET @Actual_Values =\line 'SELECT ' +\line CASE WHEN @top IS NULL OR @top < 0 THEN '' ELSE ' TOP ' + LTRIM(STR(@top)) + ' ' END +\line '''' + RTRIM(@Start_Insert) +\line ' ''+' + '''(' + RTRIM(@Column_List) + '''+' + ''')''' +\line ' +''VALUES(''+ ' + @Actual_Va
lues + '+'')''' + ' ' +\line COALESCE(@from,' FROM ' + CASE WHEN @owner IS NULL THEN '' ELSE '[' + LTRIM(RTRIM(@owner)) + '].' END + '[' + rtrim(@table_name) + ']' + '(NOLOCK)') +\line ' ' + @where\line END\line ELSE IF (@include_column_list = 0)\line BEGIN\line SET @Actual_Values =\line 'S
ELECT ' +\line CASE WHEN @top IS NULL OR @top < 0 THEN '' ELSE ' TOP ' + LTRIM(STR(@top)) + ' ' END +\line '''' + RTRIM(@Start_Insert) +\line ' '' +''VALUES(''+ ' + @Actual_Values + '+'')''' + ' ' +\line COALESCE(@from,' FROM ' + CASE WHEN @owner IS NULL THEN '' ELSE '[' + LT
RIM(RTRIM(@owner)) + '].' END + '[' + rtrim(@table_name) + ']' + '(NOLOCK)') +\line ' ' + @where\line END\line --Determining whether to ouput any debug information\line IF @debug_mode =1\line BEGIN\line PRINT '/*****START OF DEBUG INFORMATION*****'\line PRINT 'Beginning of the INSERT statem
ent:'\line PRINT @Start_Insert\line PRINT ''\line PRINT 'The column list:'\line PRINT @Column_List\line PRINT ''\line PRINT 'The SELECT statement executed to generate the INSERTs'\line PRINT @Actual_Values\line PRINT ''\line PRINT '*****END OF DEBUG INFORMATION*****/'\line PRINT ''\line END\line \line --PRINT '--INSERTs
 generated by ''spgenerate_inserts_2'' stored procedure written by Vyas'\line --PRINT '--Build number: 22'\line --PRINT '--Problems/Suggestions? Contact Vyas @ vyaskn@hotmail.com'\line --PRINT '--http://vyaskn.tripod.com'\line PRINT ''\line PRINT 'SET NOCOUNT ON'\line PRINT ''\line --Determ
ining whether to print IDENTITY_INSERT or not\line IF (@IDN <> '')\line BEGIN\line PRINT 'SET IDENTITY_INSERT ' + QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + QUOTENAME(@table_name) + ' ON'\line PRINT 'GO'\line PRINT ''\line END\line IF @disable_constraints = 1 AND (OBJECT_ID(QUOTENAME(C
OALESCE(@owner,USER_NAME())) + '.' + @table_name, 'U') IS NOT NULL)\line BEGIN\line IF @owner IS NULL\line BEGIN\line SELECT 'ALTER TABLE ' + QUOTENAME(COALESCE(@target_table, @table_name)) + ' NOCHECK CONSTRAINT ALL' AS '--Code to disable constraints temporarily'\line END\line ELSE\line BE
GIN\line SELECT 'ALTER TABLE ' + QUOTENAME(@owner) + '.' + QUOTENAME(COALESCE(@target_table, @table_name)) + ' NOCHECK CONSTRAINT ALL' AS '--Code to disable constraints temporarily'\line END\line PRINT 'GO'\line END\line PRINT ''\line PRINT 'PRINT ''Inserting values into ' + '[' + RTRI
M(COALESCE(@target_table,@table_name)) + ']' + ''''\line --All the hard work pays off here!!! You'll get your INSERT statements, when the next line executes!\line EXEC (@Actual_Values)\line PRINT 'PRINT ''Done'''\line PRINT ''\line IF @disable_constraints = 1 AND (OBJECT_ID(QUOTEN
AME(COALESCE(@owner,USER_NAME())) + '.' + @table_name, 'U') IS NOT NULL)\line BEGIN\line IF @owner IS NULL\line BEGIN\line SELECT 'ALTER TABLE ' + QUOTENAME(COALESCE(@target_table, @table_name)) + ' CHECK CONSTRAINT ALL' AS '--Code to enable the previously disabled constraint
s'\line END\line ELSE\line BEGIN\line SELECT 'ALTER TABLE ' + QUOTENAME(@owner) + '.' + QUOTENAME(COALESCE(@target_table, @table_name)) + ' CHECK CONSTRAINT ALL' AS '--Code to enable the previously disabled constraints'\line END\line PRINT 'GO'\line END\line PRINT ''\line IF (@IDN <> '')\line BEGIN\line PRINT 
'SET IDENTITY_INSERT ' + QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + QUOTENAME(@table_name) + ' OFF'\line PRINT 'GO'\line END\line PRINT 'SET NOCOUNT OFF'\line SET NOCOUNT OFF\line RETURN 0 --Success. We are done!\line END}
\par }